<?php
require('config.php');

        $user_id=$_REQUEST['user_id'];
        $shopName=$_REQUEST['shopName'];
        $sheng=$_REQUEST['sheng'];
        $shi=$_REQUEST['shi'];
        $qu=$_REQUEST['qu'];
        $shopAddress=$_REQUEST['shopAddress'];
        $xxAddress=$_REQUEST['xxAddress'];
        $name=$_REQUEST['name'];
        $phone=$_REQUEST['phone'];
        $email=$_REQUEST['email'];
        $yyzz=$_REQUEST['yyzz'];
        $id_number=$_REQUEST['id_number'];
        $src1=$_REQUEST['src1'];
        $src2=$_REQUEST['src2'];
        $src3=$_REQUEST['src3'];
        $lon=$_REQUEST['lon'];
        $lat=$_REQUEST['lat'];
        $yiji_id=0;
        $erji_id=0;
        if(isset($_REQUEST['yiji_id'])) $yiji_id=$_REQUEST['yiji_id'];
        if(isset($_REQUEST['erji_id']))  $erji_id=$_REQUEST['erji_id'];
		$sql="select * from `".$oto."_shops` where `userId`='{$user_id}' and shopFlag='1'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$shops_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(!isset($shops_info))
		{
			$shopSn=time();
			$time=date('Y-m-d H:i:s');
			$sql="INSERT INTO ".$oto."_shops (`shopSn`,`userId`,`areaId1`,`areaId2`,`areaId3`,`shopName`,`shopTel`,`shopCompany`,`shopAddress`,`createTime`,`latitude`,`longitude`,`idNo`,`idImg`,`idRevImg`,`permitImg`,`permitNo`,`goodsCatId1`,`goodsCatId2`) VALUES ('$shopSn','$user_id','$sheng','$shi','$qu','$shopName','$shopName','$phone','$xxAddress','$time','$lat','$lon','$id_number','$src2','$src3','$src1','$yyzz','$yiji_id','$erji_id')";
            $result=$db->query($sql);
            //file_put_contents("tsxx.txt", "\r\n22:".$sql."\r\n", FILE_APPEND);
            if($result)
            {
            	$data[0]['pan']=1;
				$data[0]['msg']='提交成功，请等待审核！';
            }
            else
            {
            	$data[0]['pan']=-1;
				$data[0]['msg']='提交失败，请稍后再试！';
            }
		}
		else
		{
			if($shops_info[0]['shopStatus']<0)
			{
				$shop_id=$shops_info[0]['shopId'];
				$sql="update ".$oto."_shops set areaId1='{$sheng}',areaId2='{$shi}',areaId3='{$qu}',shopName='{$shopName}',shopCompany='{$shopName}',shopTel='{$phone}',shopAddress='{$xxAddress}',shopStatus='0',idNo='{$id_number}',idImg='{$src2}',idRevImg='{$src3}',permitImg='{$src1}',premitNo='{$yyzz}',goodsCatId1='{$yiji_id}',goodsCatId2='{$erji_id}' where shopId='{$shopId}'";
				$result=$db->query($sql);
				//file_put_contents("tsxx.txt", "\r\n11:".$sql."\r\n", FILE_APPEND);
				if($result)
				{
					$data[0]['pan']=1;
					$data[0]['msg']='提交成功，请等待审核！';
				}
				else
				{
					$data[0]['pan']=-1;
					$data[0]['msg']='提交失败，请稍后再试！';
				}
			}
			else
			{
				if($shops_info[0]['shopStatus']==0)
				{
					$data[0]['pan']=-1;
					$data[0]['msg']='资料已提交，请等待审核！';
				}
				else if($shops_info[0]['shopStatus']==1)
				{
					$data[0]['pan']=-1;
					$data[0]['msg']='您已经是商家了！';
				}
				else
				{
					$data[0]['pan']=-1;
					$data[0]['msg']='暂时不能申请入驻，请联系平台管理';
				}
			}
		}
		echo json_encode($data);
?>